﻿package reverse_integer;
/*
没什么技巧，普通解法
*/
public class Solution {
    public int reverse(int x) {
        boolean flag = true;
        if (x < 0) {
            flag = false;
            x = 0 - x;
        }
        String reverse = x + "";
        char tempCharArray[] = reverse.toCharArray();
        for (int i = 0; i < tempCharArray.length / 2; i++) {
            char temp = tempCharArray[tempCharArray.length - i - 1];
            tempCharArray[tempCharArray.length - 1 - i] = tempCharArray[i];
            tempCharArray[i] = temp;
        }
        String result = new String(tempCharArray);
        if (!flag) {
            result = "-" + result;
        }
        try {
            Integer.parseInt(result);
        } catch (Exception e) {
            return 0;
        }
        return Integer.parseInt(result);
    }
}
